FROM registry.cn-hangzhou.aliyuncs.com/coffen/python:3.11-slim
MAINTAINER coffen <418320769@qq.com>

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

ENV TZ "Asia/Shanghai"

WORKDIR /app


# 网络响应太慢了，封装到镜像了 BEGIN
# ------------ 初始化APT源 ------------
#RUN echo "deb http://deb.debian.org/debian bullseye main" > /etc/apt/sources.list \
#    && echo "deb http://deb.debian.org/debian bullseye-updates main" >> /etc/apt/sources.list \
#    && echo "deb http://security.debian.org/debian-security bullseye-security main" >> /etc/apt/sources.list

# ------------ 替换为清华源 ------------
#RUN sed -i "s@http://deb.debian.org@https://mirrors.aliyun.com@g" /etc/apt/sources.list \
#    && sed -i "s@http://security11.debian.org@https://mirrors.aliyun.com/debian-security@g" /etc/apt/sources.list


#RUN apt-get update && apt-get install -y \
#    gcc \
#    python3-dev \
#    default-libmysqlclient-dev \
#    build-essential \
#    pkg-config \
#    && rm -rf /var/lib/apt/lists/*

# 网络响应太慢了，封装到镜像了 END

COPY . .

# PIP清华源
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# RUN pip install mysqlclient --find-links=file:///app/python_packs

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt && \
    echo '{"release_type": "settings_prod", "release_sub_type": "_docker"}' > ./cfg/release.json && \
    rm -f logs/*

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "book_management.wsgi"]